package bd403.utils;

import bd403.Backend.DrinkDB;


/*
 * A Stub DB that uses another member's server to execute tests for drinkStorage
 * Main author: Justin Hon Lee
 */

public class DrinkDBStub extends DrinkDB {
	private static DrinkDBStub instance;
	private final String HTTP_CLEAR_SUFFIX = "var1=clearDB";
	private DrinkDBStub() {
	
		// Singleton pattern, exists to guard against instantiation.
	}
	
	/* Returns an instance of this singleton DrinkDB. If DrinkDB has not yet been
	 * created, a DrinkDB instance is created and returned. Otherwise an instance
	 * of the single DrinkDB is returned.
	 */
	public static DrinkDBStub getInstance() {
		if (instance == null) {
			instance = new DrinkDBStub();
		}
		return instance;
	}
	
	/* Modifies the URL of the database to connect to. We used a test database for unit tests.
	 */
	public void changeUrl() {
		URL_START = "http://cubist.cs.washington.edu/~jbuck15/index.php?";
	}
	
	/* Clears the test database or drinks, reviews, and users.
	 */
	public void clearDB() {
		httpConn(URL_START + HTTP_CLEAR_SUFFIX);
	}
}
